package com.cw.data.handler;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import com.cw.action.panel.CheckPanel;
import com.cw.action.panel.DataCheckPanel;
import com.cw.maintenance.AddDataDialog;
import com.cw.po.Lottery;

public class DataHandler extends AbstractHandler {

	public DataHandler(Lottery lt) {
		super(lt);
	}

	@Override
	public void loadData(Vector<Vector<String>> values, DefaultTableModel dtm) {
		for(int i=0;i<values.size();i++){
			Vector<String> vec = values.elementAt(i);
			dtm.addRow(new Vector());
			for(int j=0;j<vec.size();j++){
				String v = vec.get(j);
				if(j<2){						
					dtm.setValueAt(v, i, j);
				}else{
					dtm.setValueAt(v, i, Integer.parseInt(v)+2+(j-2)*10);
				}
			}
		}
	}
	
	@Override
	public void insertData(Vector<String> vec, DefaultTableModel dtm) {
		dtm.addRow(new Vector());
		int row = dtm.getRowCount()-1;
		for(int j=0;j<vec.size();j++){
			String v = vec.get(j);
			if(j<2){
				v = v.substring(1, v.length()-1);
				dtm.setValueAt(v, row, j);
			}else{
				dtm.setValueAt(v, row, Integer.parseInt(v)+2+(j-2)*10);
			}
		}
	}

	@Override
	public CheckPanel getChkPanel(AddDataDialog add) {
		// TODO Auto-generated method stub
		return new DataCheckPanel(add, lottery);
	}

	@Override
	public void createColumn(DefaultTableModel dtm, Lottery lt) {
		for(int i=0;i<lt.getNum();i++){
			for(int j=Integer.parseInt(lt.getMinnum());j<=Integer.parseInt(lt.getMaxnum());j++){
				dtm.addColumn(j);
			}
		}
	}
	
}
